/**
 * 
 */
package com.softme.trade.control;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.softme.trade.model.Firm;
import com.softme.trade.model.dao.FirmDAO;
import com.softme.trade.model.dao.UserDAO;
import com.softme.trade.util.BeanFactory;
import com.softme.trade.view.components.ColumnModel;
import com.softme.trade.view.components.DataTableUtils;

/**
 * @author meyer
 */
@ViewScoped
@ManagedBean
public class FirmController implements  Serializable
{

	private static final long serialVersionUID = 1L;

	private Firm firm = new Firm();


	private List<Firm> listFirms = new ArrayList<Firm>();

	private FirmDAO firmDAO;


	public FirmController()
	{
		this.updateScreen();
		// TODO Auto-generated constructor stub
	}

	
	
	/**
	 * Limpa os campos input e atualiza a lista de empresas cadastrados
	 */
	private void updateScreen()
	{
		this.firm = new Firm();
		this.listFirms = this.getDAO().loadAll();
	}


	/**
	 * Grava novo registro ou atualiza um registro
	 */
	public void save()
	{
		this.getDAO().saveOrUpdate(getFirm());
		updateScreen();
	}



	public void delete()
	{
		this.getDAO().delete(this.getFirm());
		this.updateScreen();
	}

	public void create()
	{
		this.firm = new Firm();
	}

	public Firm getFirm()
	{
		return this.firm;
	}
	

	public void setFirm(Firm firm)
	{
		this.firm = firm;
	}

	public FirmDAO getDAO()
	{
		if (this.firmDAO == null || this.firmDAO.getHibernateTemplate() == null)
			this.firmDAO = (FirmDAO) BeanFactory.getBean("firmDAO", FirmDAO.class);

		return this.firmDAO;
	}

	public List<Firm> getListFirms()
	{
		return this.listFirms;
	}

}
